package com.zbf.auth.auth;

import com.zbf.auth.user.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 作者: LCG
 * 日期: 2020/6/9 10:41
 * 描述:
 */

@Component
public class TestMEnuService {

    @Autowired
    private TestMenuDao testMenuDao;


    public List<Menu> getMenus(){


        List<Menu> firstMenu = testMenuDao.getFirstMenu();

        this.nextMenu(firstMenu);

        return firstMenu;
    }


    public void nextMenu(List<Menu> firstMenu){

        for (Menu menu:firstMenu) {
            //去取上级菜单的下级菜单
            List<Menu> nextMenu = testMenuDao.getNextMenu(""+menu.getCode(), menu.getLeval()+1);
            if(nextMenu.size()>0){
                menu.setListMenu(nextMenu);
                //再查询再下一级菜单
                this.nextMenu(nextMenu);
            }else{
                break;
            }
        }

    }

}
